package com.xsjt.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xsjt.bean.User;
import com.xsjt.mapper.UserMapper;
import com.xsjt.service.UserService;

/**
 * 控制层
 * @author Administrator
 *
 */
@Controller
public class HelloController {

    private Logger logger = LoggerFactory.getLogger(HelloController.class);
    @Resource
    private UserMapper userMapper;
    
    @Resource
    private UserService userService;
    
    
    @RequestMapping(value = "/users",method = RequestMethod.GET)
    public @ResponseBody User testUserDao(){
        User user = userMapper.findById(1);
        logger.info("查询结果：" + user);
        return user;
    }
    
    @RequestMapping("/add")
    @ResponseBody
    public String add(String username, String rolename){
    	boolean flag = userService.addUserAndRole(new User(username, "12345" , rolename));
    	if(flag){
    		return "增加成功！";
    	}
		return "增加失败！";
    }
    
    
    @RequestMapping("/qryUsers")
    @ResponseBody
    public List<User> qryUsers() {
    	Map<String, Object> map = new HashMap<String, Object>();
    	map.put("pageNum", 1);
    	map.put("pageSize", 2);
    	
    	List<User> list = userService.findUsers(map);
    	return list;
    }

}
